import { queryAssetInfoSubByAssetId } from '@/api/asset'
import { queryContractById } from '@/api/leaseContract'

export const AssetSubMixin = {
  data () {
    return {
      searchOptions: [],
      roomStatus: ''
    }
  },
  methods: {
    changeLease (t) {
      let that = this
      if (t) {
        queryContractById({ id: t }).then((res) => {
          if (res.success) {
            that.$nextTick(() => {
              that.form.setFieldsValue({ assetId: "", customerId: "" })
            })
            that.isReadOnly = true
            that.selectSub(res.result.assetId, "")
          }
        })
      } else {
        that.isReadOnly = false
      }
    },
    selectSub (assetId, assetSubIds) {
      // this.$set(this.form, 'assetSubIds', '')
      this.selectSub1(assetId, assetSubIds)
      this.$nextTick(() => {
        this.form.setFieldsValue({ assetSubIds: '' })
      })
    },
    selectSub1 (assetId, assetSubIds) {
      let that = this
      if (!assetSubIds) {
        assetSubIds = ''
      }
      if (!assetId) {
        assetId = ''
      }
      // let assetIdLeng = assetId.split(",")
    // && assetIdLeng.length == 1
      if (assetId) {
        queryAssetInfoSubByAssetId({
          assetInfoIds: assetId,
          // roomStatus: this.roomStatus
        }).then(res => {
          console.log(res)
          that.searchOptions = res.result
          that.validatorRules.assetSubIds.rules[0].required = that.searchOptions.length > 0
          // if (this.searchOptions.length > 0) {
          // } else
          that.$nextTick(() => {
            that.form.setFieldsValue({ assetSubIds: assetSubIds })
          })
        })
      } else {
        this.validatorRules.assetSubIds.rules[0].required = false
        this.searchOptions = []
      }
    }
  }
  // created() {
  //   this.hello();
  // },
}